import 'package:fbdplugin/bd_map_page.dart';
import 'package:fbdplugin/center_location_page.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}):super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String address = '成都天府三街';
  String latitude = '30.553249';
  String longitude = '104.068307';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          '测试百度地图'
        ),
      ),
      body: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text('宜宾珙县-->成都天府三街'),
          //展示地图
          MaterialButton(onPressed: ()=>toBdMapPage(),color: Colors.lightBlue,child: Text('展示地图'),),
          SizedBox(height: 10,),
          //拾取坐标
          MaterialButton(onPressed: ()=>toLocationPage(),color: Colors.red,child: Text('拾取坐标'),),
          Text('拾取的位置：address=$address,latitude=$latitude,longitude=$longitude'),
        ],
      ),
    );
  }

  toBdMapPage() {
    Navigator.push(context, MaterialPageRoute(builder: (_)=>
       BDMapPage(
        sendAddress: '宜宾珙县',
        sendLatitude: 28.44305,
        sendLongitude: 104.717872,
        receiveAddress: '成都天府三街',
        receiveLatitude: 30.553249,
        receiveLongitude: 104.068307,
      )
    ));
  }

  toLocationPage() {
    Navigator.push(context, MaterialPageRoute(builder: (_)=>
        CenterLocationPage(
          isEdit: true,
          appBarBg: Colors.teal,
          latitude: latitude,
          longitude: longitude,
          address: address,
        )
    )).then((value){
      print('--->value=${value}');
      if((value!=null)&&(value is Map)){
        //{'latitude':latitude,'longitude':longitude,'address':address,}
         address = value['address'];
         latitude = value['latitude'];
         longitude = value['longitude'];
        print('--->address=${address},latitude=${latitude},longitude=${longitude},');
        setState(() {});

        // addressVo?.latitude = latitude;
        // addressVo?.longitude = longitude;
        // addressVo?.addressInfo = address;
        // if(addressVo?.latitude=='null')addressVo?.latitude='0';
        // if(addressVo?.longitude=='null')addressVo?.longitude='0';
        // print('--->addressVo 2=${addressVo?.toJson()}');
        // setState(() {});
        // addressDetailController.text = addressVo?.addressInfo??'';
      }
    });
  }
}
